import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Watersheds {
	private static class Cell {
		int r, c;
		public Cell(int r, int c) {
			this.r = r;
			this.c = c;
		}
		public boolean equals(Cell cell) {
			return r == cell.r && c == cell.c;
		}
	}
	private static Cell flowsTo(int[][] land, Cell from) {
		Cell to = new Cell(from.r, from.c);
		if(from.r > 0 && land[from.r - 1][from.c] < land[to.r][to.c]) {
			to.r = from.r - 1;
			to.c = from.c;
		}
		if(from.c > 0 && land[from.r][from.c - 1] < land[to.r][to.c]) {
			to.r = from.r;
			to.c = from.c - 1;
		}
		if(from.c < land[0].length - 1 && land[from.r][from.c + 1] < land[to.r][to.c]) {
			to.r = from.r;
			to.c = from.c + 1;
		}
		if(from.r < land.length - 1 && land[from.r + 1][from.c] < land[to.r][to.c]) {
			to.r = from.r + 1;
			to.c = from.c;
		}
		return to;
	}
	public static void labelSource(int[][] land, char[][] label, Cell cell, char curlabel) {
		label[cell.r][cell.c] = curlabel;
		if(cell.r > 0) {
			Cell northCell = new Cell(cell.r - 1, cell.c);
			if(flowsTo(land, northCell).equals(cell))
				labelSource(land, label, northCell, curlabel);
		}
		if(cell.c > 0) {
			Cell westCell = new Cell(cell.r, cell.c - 1);
			if(flowsTo(land, westCell).equals(cell))
				labelSource(land, label, westCell, curlabel);
		}
		if(cell.c < land[0].length - 1) {
			Cell eastCell = new Cell(cell.r, cell.c + 1);
			if(flowsTo(land, eastCell).equals(cell))
				labelSource(land, label, eastCell, curlabel);
		}
		if(cell.r < land.length - 1) {
			Cell southCell = new Cell(cell.r + 1, cell.c);
			if(flowsTo(land, southCell).equals(cell))
				labelSource(land, label, southCell, curlabel);
		}
	}
	public static void main(String[] args) throws IOException {
		BufferedReader rdr = new BufferedReader(new InputStreamReader(System.in));
		try {
			int T = Integer.parseInt(rdr.readLine());
			for(int t = 1; t <= T; t++) {
				String HW[] = rdr.readLine().split(" ");
				int H = Integer.parseInt(HW[0]);
				int W = Integer.parseInt(HW[1]);
				int land[][] = new int[H][W];
				for(int h = 0; h < H; h++) {
					String landRow[] = rdr.readLine().split(" ");
					for(int w = 0; w < W; w++)
						land[h][w] = Integer.parseInt(landRow[w]);
				}
				char label[][] = new char[H][W];
				char curlabel = 'a';
				for(int r = 0; r < H; r++) {
					for(int c = 0; c < W; c++) {
						if(label[r][c] < 'a') {
							// find sink
							Cell sink = new Cell(r, c);
							while(true) {
								Cell to = flowsTo(land, sink);
								if(to.equals(sink))
									break;
								else
									sink = to;
							}
							
							// label sources to sink
							labelSource(land, label, sink, curlabel);
							
							curlabel++;
						}
					}
				}
				System.out.println("Case #" + t + ":");
				for(int r = 0; r < H; r++) {
					System.out.print(label[r][0]);
					for(int c = 1; c < W; c++)
						System.out.print(" " + label[r][c]);
					System.out.println();
				}
			}
		} finally {
			rdr.close();
		}
	}
}
